<?php
$orderby = get_major_key(array('rank' => 'DESC', 'id' => 'DESC'));
$oBrand = new Brand();

if(!empty($_GET['btnExport'])){	// 导出
	$list = $oBrand->get_list('*', $_GET, $orderby, 1, 65536, $offset = 0);
	if(!empty($list['list']) && is_array($list['list'])){
		$data = array();
		foreach($list['list'] as $row){
			$row['addtime'] 	= ftime($row['addtime']);
			$row['updatetime']	= ftime($row['updatetime']);
			$data[] = $row;
		}
		$headers = array(
			'id'			=> array('title' => 'ID',		'width' => '6'),
			'name'			=> array('title' => '名称',		'width' => '25',	'wrap' => true),
			'mark'			=> array('title' => '标识', 	'width' => '12.5'),
			'url'			=> array('title' => 'URL', 		'width' => '50',	'wrap' => true),
			// 'content'		=> array('title' => '介绍', 	'width' => '50',	'wrap' => true),
			'rank'			=> array('title' => '排序', 	'width' => '8'),
			'addtime'		=> array('title' => '添加时间', 'width' => '18'),
			'updatetime'	=> array('title' => '更新时间', 'width' => '18'),
			'logo'			=> array('title' => 'LOGO', 	'width' => 'auto'),
		);
		if($list['total'] > 5000){	// 导出超过5000时用CSV
			export_csv($data, $headers, '_E_品牌_'.date('Ymd_His').'.csv');
		}else{
			$oExcel = new Excel();
			$oExcel->export($headers, $data, '_E_品牌_'.date('Ymd_His').'.xlsx');
		}
	}
	exit;
}

$list = $oBrand->get_list('*', $_GET, $orderby, $__page, $__pagesize);
if(!empty($list['list'])){
	
	// 主键排序字段
	make_major_key_options($major_key_arr = array(
		'id'	=> '添加时间',
		'rank'	=> '排序号',
	));
	
	foreach($list['list'] as $key => $row){
		if(empty($row['url'])){
			if(empty($row['filename'])){
				$row['url'] = PUB_DIR.'brand/'.time_to_path($row['addtime']).'/'.$row['id'].'.html';
			}else{
				$row['url'] = PUB_DIR.'brand/'.$row['filename'].'.html';
			}
		}
		$row['addtime'] = ftime($row['addtime']);
		$row['updatetime'] = ftime($row['updatetime']);
		$list['list'][$key] = $row;
	}
	$vars['list'] = $list['list'];
	$vars['pagelist'] = $list['pagelist'];
}
?>